-
Notifications
You must be signed in to change notification settings - Fork 2k
Fix: handle JSON parse error in streaming tool calls #4274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Minu Kim <[email protected]>
import java.util.List; | ||
import java.util.function.BiPredicate; | ||
|
||
import org.jetbrains.annotations.NotNull; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't use this annotation for not null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@markpollack I’ve removed ToolOnFinishPredicate.java and applied the fix directly in OpenAiChatModel.
when the LLM returns malformed or invalid JSON during streaming, the code explicitly throws an exception.
The PR looks incomplete. I've commented on the issue thread for further clarification. #4274 |
Signed-off-by: Minu Kim <[email protected]>
@markpollack However, the OpenAIChatModel was not properly detected when the LLM returned an invalid response. |
Overview
This PR fixes a JSON parsing error that occurs when handling streaming tool calls in Spring AI.
Related issue: spring-projects/spring-ai#4250
Why
com.fasterxml.jackson.core.JsonParseException: Unexpected close marker ']': expected '}'
stream()
) calls.call()
) are not affected.What Changed
ToolExecutionEligibilityPredicate
implementation:ToolOnFinishPredicate
.finishReason = "tool_calls"
or"stop"
).How to Use
Example usage: